import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import autoprefixer from 'autoprefixer';
import vitePluginImp from 'vite-plugin-imp';
import path from 'path';

const URI = 'http://58.33.188.228:21300';

// https://vitejs.dev/config/
export default defineConfig({
  server: {
    port: 3000,
    strictPort: true,
    fs: {
      strict: true,
      deny: [
        'package.json',
        '.gitignore',
        '.eslintrc.cjs',
        'tsconfig.json',
        'tsconfig.*.json',
        'vite.config.ts',
        '*.lock',
      ],
    },
    proxy: {
      '/api': {
        target: URI,
        changeOrigin: true,
      },
    },
  },
  appType: 'spa',
  resolve: {
    alias: {
      src: path.resolve('src'),
    },
  },
  css: {
    modules: {
      localsConvention: 'camelCase',
    },
    postcss: {
      plugins: [autoprefixer],
    },
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
        modifyVars: {
          '@primary-color': '#4377FE',
        },
      },
    },
  },
  plugins: [
    react({
      include: /\.(js|jsx|ts|tsx)$/,
      babel: {
        plugins: [
          'transform-typescript-metadata',
          ['@babel/plugin-proposal-decorators', { legacy: true }],
          '@babel/plugin-proposal-class-properties',
        ],
        exclude: [/node_modules[\\/]core-js/],
        compact: false,
      },
    }),
    vitePluginImp({
      libList: [
        {
          libName: 'antd',
          style: (name) => `antd/es/${name}/style`,
        },
      ],
    }),
  ],
});
